$(function(){	
  $("#list").jqGrid({
    	url:"workflow/data/query-data!watch",
    	postData:{
    		"workflowId":workflowId
    	},
        datatype: "json",
        mtype: 'GET',
        colNames:['流程名','步骤名称','活动名称','办理人','开始日期','结束日期','办理状态'],
        colModel :[ 
        {name:'workflowName', index:'workflowName', width:150,formatter:nameFormater},
        {name:'stepName', index:'actionName', width:150} ,
        {name:'actionName', index:'actionName', width:150} ,
        {name:'owner', index:'owner', width:150} ,
        {name:'startDate', index:'startDate', width:150 },
        {name:'finishDate', index:'finishDate', width:150 },
        //{name:'state', index:'state', width:80 ,formatter:stateFormatter}, 
        {name:'status', index:'status', width:100 ,formatter:statusFormatter}
      ],
      pager:'#pager',
      rowNum:10,
      rowList:[10,20,30],
      sortname: 'finishDate',
      sortorder: 'desc',
      viewrecords: true,
      caption: '流程监控',
      width:'750',
      height:'300',
      jsonReader: {
  		repeatitems : false,
  		id: "0"
  	  }  
    }); 
});

function nameFormater(cellvalue,optionss,rowObject){
	return cellvalue+"["+rowObject['workflowId']+"]";
}
function statusFormatter(cellvalue,optionss,rowObject){
	switch(cellvalue){
	  case 'Finished':return '完成';
	  case 'Underway':return '在办';
	  default :return '未知';
	}
}

function stateFormatter(cellvalue,optionss,rowObject){
     
     switch(cellvalue){
     case 0:return "开始";
     case 1:return "激活";
     case 2:return "挂起";
     case 3:return "中断";
     case 4:return "完成";
     case -1:return "未知";
     }

}

function formFormatter(cellvalue,options,rowObject){
	 var param = {
           "workflowId":cellvalue,
           "workflowName":rowObject['workflowName'],
           "stepId":rowObject['stepId'],
           "showOnly":true
	        };
    var url = navObj.form.core+navObj.form.preview+"?"+$.param(param);
	var link = $("<a></a>");
    link.attr("href","javascript:viewfrom('"+url+"');");
    link.text("表单");
    return jQuery("<span></span>").append(link).html();

}  
function viewform(url){
	window.open(url,"formwindow");
}